package com.umiwe.permission.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.umiwe.entity.UmiweRolePermission;
import com.umiwe.entity.UmiweRolePermissionVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;


import java.util.List;


@Mapper
public interface RolePermissionMapper extends BaseMapper<UmiweRolePermissionVO> {


    @Select("SELECT ur.id as roleId,ur.name as roleName,ur.status as roleStatus,ur.is_delete as roleIsDelete,ur.system_id as roleSystemId," +
            "up.id as perId,up.name as perName,up.parent_id as perParentId,up.uri as perUri,up.status as perStatus,up.is_delete as perIsDelete" +
            " FROM umiwe_role ur INNER JOIN umiwe_role_permission urp ON ur.id = urp.role_id INNER JOIN umiwe_permission up ON urp.permission_id = up.id and up.status =1" +
            " and up.is_delete = 2 where ur.id = #{roleId}")
    List<UmiweRolePermissionVO> getRolePermissionByRoleId(Integer roleId);
    /**
     *基于角色id删除角色权限关系表数据
     */

    @Delete("delete from umiwe_role_permission where ${roleId}=#{id}")
    int deleteRolePer(String roleId,Integer id);
    /**
     * 基于权限id删除角色权限关系数据
     */
    @Delete("delete from umiwe_role_permission where ${permissionId}=#{id}")
    int deletePerRole(String permissionId,Integer id);
    /**
     * 保存角色权限关系数据
     * @param roleId
     * @param umiweRolePermission
     * @return
     */
    int insertRolePer(Integer roleId,UmiweRolePermission umiweRolePermission);
}
